package com.tengju.bff.interfaces.manage.star.assembler;

import com.google.common.collect.Lists;
import com.tengju.bff.interfaces.manage.member.sign.blacklist.vo.PageStarBlacklistVO;
import com.tengju.bff.interfaces.manage.star.vo.StarBlacklistVO;
import com.tengju.bff.interfaces.shared.MobileVO;
import com.tengju.user.application.archives.dto.PageQueryDTO;
import com.tengju.user.domain.model.sign.StarBlacklist;
import java.time.format.DateTimeFormatter;
import java.util.List;
import org.springframework.util.CollectionUtils;

public class StarBlacklistAssembler {

    public static PageStarBlacklistVO ModelToVO(List<StarBlacklist> list, PageQueryDTO pageQueryDTO,
            int total) {
        PageStarBlacklistVO pageStarBlacklistVO = new PageStarBlacklistVO();
        pageStarBlacklistVO.setPageIndex(pageQueryDTO.getPageIndex());
        pageStarBlacklistVO.setPageSize(pageQueryDTO.getPageSize());
        pageStarBlacklistVO.setTotal(total);

        if (CollectionUtils.isEmpty(list)) {
            return pageStarBlacklistVO;
        }

        List<StarBlacklistVO> starBlacklistVOS = Lists.newArrayList();
        for (StarBlacklist starBlacklist : list) {
            StarBlacklistVO vo = new StarBlacklistVO();
            vo.setStarBlacklistId(starBlacklist.getStarBlacklistId().getValue());
            vo.setIdCode(starBlacklist.getIdCode().getValue());
            vo.setMobile(new MobileVO(starBlacklist.getMobile()));
            vo.setLimitStarLevel(starBlacklist.getLimitStarLevel().getDesc());
            vo.setCreateTime(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
                    .format(starBlacklist.getCreateTime()));
            vo.setCreateBy(starBlacklist.getCreateBy());
            starBlacklistVOS.add(vo);
        }
        pageStarBlacklistVO.setStarBlacklistVOList(starBlacklistVOS);

        return pageStarBlacklistVO;
    }
}
